package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.mapper.Sms_Member_Price_Mapper;
import com.shop.service.Sms_Member_Price_Service;
import com.shop.pojo.sms.Sms_Member_Price;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品会员价格-李贝贝
 */
@Service
public class Sms_Member_Price_ServiceImpl extends ServiceImpl<Sms_Member_Price_Mapper, Sms_Member_Price> implements Sms_Member_Price_Service {


    @Autowired
    private Sms_Member_Price_Mapper sms_member_price_mapper;

    /**
     * 显示所有会员价格
     * @param pages
     * @param sms_member_price
     * @return
     */
    @Override
    public LayuiUtils<Sms_Member_Price> find_admin_sms_member_price(Page<Sms_Member_Price> pages, Sms_Member_Price sms_member_price) {
        LayuiUtils<Sms_Member_Price> layuiUtils = new LayuiUtils<>();
        QueryWrapper<Sms_Member_Price> queryWrapper = new QueryWrapper<>();
        if (sms_member_price.getSku_id() != null){
            queryWrapper.eq("sku_id",sms_member_price.getSku_id());
        }
        Page<Sms_Member_Price> pricePage = sms_member_price_mapper.selectPage(pages,queryWrapper);
        layuiUtils.setCount(pricePage.getTotal());
        layuiUtils.setData(pricePage.getRecords());
        return layuiUtils;
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @Override
    public R delete_sms_member_price(List<Long> id) {
        int i = sms_member_price_mapper.deleteBatchIds(id);
        if (i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }
}
